package com.mb.app.service.impl;


import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.mb.app.dao.TbIndexClassTypeMapper;
import com.mb.app.domain.TbIndexClassType;
import com.mb.app.service.ITbIndexClassTypeService;
import com.mb.common.config.CommonConfig;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zwl
 * @since 2019-04-16
 */
@Service
@Slf4j
public class TbIndexClassTypeServiceImpl extends ServiceImpl<TbIndexClassTypeMapper, TbIndexClassType> implements ITbIndexClassTypeService {

    @Autowired
    private CommonConfig commonConfig;


    @Override
    public List<TbIndexClassType> queryList(Map<String, Object> map) {
        List<TbIndexClassType> list = this.baseMapper.lst(map);
        return list;
    }

    @Override
    public int count(Map<String, Object> map) {
        return this.baseMapper.countt(map);
    }

    @Override
    public int update(TbIndexClassType TbIndexClassType) {
        int istre = 0;
        try {
            if (StringUtils.isNotEmpty(TbIndexClassType.getPicUrl())) {
                String PicUrl = TbIndexClassType.getPicUrl();
                PicUrl = PicUrl.replaceAll(commonConfig.getImgDomain(), "");
                TbIndexClassType.setPicUrl(PicUrl);
            }
            TbIndexClassType.setUpdateTime(new Date());
            istre = this.baseMapper.updateById(TbIndexClassType);
        } catch (Exception e) {
            log.error("update Exception", e);
        }
        return istre;
    }

    @Override
    public TbIndexClassType getDtl(Long indexTypeId) {
        TbIndexClassType TbIndexClassType = this.baseMapper.selectById(indexTypeId);
        if (TbIndexClassType != null && StringUtils.isNotEmpty(TbIndexClassType.getPicUrl())) {
            TbIndexClassType.setPicUrl(commonConfig.getImgDomain() + TbIndexClassType.getPicUrl());
        }
        return TbIndexClassType;
    }

    @Override
    public boolean NameIdExit(Map<String, Object> params) {
        boolean exit;
        exit = this.baseMapper.selectByInfo(params).size() > 0;
        return exit;
    }

}
